package com.daiyu.sharding.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.daiyu.sharding.domain.entity.Order;
import com.daiyu.sharding.domain.request.OrderReq;
import com.daiyu.sharding.domain.response.OrderRsp;
import com.daiyu.sharding.mapper.OrderMapper;
import com.daiyu.sharding.service.OrderService;
import kotlin.jvm.internal.Lambda;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：chenlong
 * @filename OrderServiceImpl
 * @date 2022-09-12 16:57
 * @description：orderservice实现类
 */
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<OrderRsp> getOrderInfo() {
        LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<Order>();
        List<Order> list = orderMapper.selectList(queryWrapper);
        List<OrderRsp> orderList = new ArrayList<>();
        list.stream().forEach(order -> {
            OrderRsp orderRsp = new OrderRsp();
            BeanUtils.copyProperties(order, orderRsp);
            orderList.add(orderRsp);
        });
        return orderList;
    }

    @Override
    public int insertOrder(Order order) {
        return orderMapper.insert(order);
    }

}
